package dasregistry.ontology.browsing;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * Servlet implementation class proxy
 */
public class TreeServlet extends HttpServlet {
	
       
   

	/**
     * @see HttpServlet#HttpServlet()
     */
    public TreeServlet() {
        super();
        System.out.println("loading Tree proxy");
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String urlString=request.getParameter("url");
		//example= http://www.ebi.ac.uk/ontology-lookup/json/termchildren?termId=SO:0000400&ontology=SO&depth=100
		urlString=urlString.replace(" ","+");
		System.out.println("urlString="+urlString);
		
		PrintWriter out = response.getWriter();
//		FileWriter out = null;
//		try {
//			out = new FileWriter(
//					"/Users/jw12/workspaceJune2009/dasregistry/WebContent/tree/_docs/_json_data.json");
//		} catch (IOException e1) {
//			// TODO Auto-generated catch block
//			e1.printStackTrace();
//		}
		OLSOntologyReader reader=new OLSOntologyReader();
		System.out.println("loaded reader");
		reader.getOntologyAsJSON(urlString, out);
		
	   }  // end of main


		
		
		
		
	

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
